package com.itheima.springbootwebtlias.mapper;

import com.itheima.springbootwebtlias.pojo.StuQueryParam;
import com.itheima.springbootwebtlias.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface StuMapper {

    // 分页 + 条件查询学员
    List<Student> selectByCondition(StuQueryParam queryParam);

    // 添加学员
    @Insert("insert into student(id, name, no, gender, phone, id_card, " +
            "is_college, address, degree, graduation_date, clazz_id,create_time,update_time) "
             + "values (null,#{name},#{no},#{gender},#{phone},#{idCard}," +
            "#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    // 批量删除学员
    void deleteBatch(List<Integer> ids);

    // 根据id查询学员
    @Select("select * from student where id = #{id}")
    Student selectById(Integer id);

    //  修改学员
    void update(Student student);

    //  增加学员的违规次数和违规分数
    @Select("update student set violation_count = violation_count + 1, " +
            "violation_score = violation_score + #{score} where id = #{id}")
    void violation(Integer id, Integer score);

    // 根据班级id查询学员数量
    @MapKey("name")
    List<Map> stuCount();

    //  根据学历查询学员数量
    @MapKey("name")
    List<Map> degreeCount();
}
